#!/bin/bash

# fake synology info
if [ ! -f /etc/synoinfo.conf ];
then
  rand=$(cat /proc/sys/kernel/random/uuid | awk -F '-' '{print $1}')
  echo "unique=\"synology_${rand}_720+\"" > /etc/synoinfo.conf
fi

# generate config
echo '{"port":5050, "internal": false, "dir":"/downloads"}' > /root/pan-xunlei-com/config.json

# rm dockerenv
rm /.dockerenv 2>/dev/null

# move to tmp
mkdir -p /tmp/go-build/pan-xunlei-com /var/packages/pan-xunlei-com/target/var
cp -rvf /root/pan-xunlei-com/* /tmp/go-build/pan-xunlei-com/

# patch binaries
perl -pi -e 's/mounts/status/' /tmp/go-build/pan-xunlei-com/target/xunlei-pan-cli*

# run
/tmp/go-build/pan-xunlei-com/xunlei_cgi
